package com.honey.generator.java;

import com.honey.compilation.java.AbstractClass;
import com.honey.compilation.java.AbstractJavaCompilation;
import com.honey.compilation.java.Clazz;
import com.honey.compilation.java.InnerClass;
import com.honey.compilation.java.InnerEnum;
import com.honey.compilation.java.Interface;
import com.honey.core.dbmapping.introspect.IntrospectSchema;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.generator.java.extension.point.GeneratorJavaClass;

/**
 * java 类编译工厂
 * @author Administrator
 *
 */
class CompilationFactory {
	
	/**
	 * 编译java类
	 * @param generatorJavaClass
	 */
	public static AbstractJavaCompilation doJavaCompilation(GeneratorJavaClassPlugin belongPlugin, GeneratorJavaClass generatorJavaClass,IntrospectSchema schema, IntrospectSchemaColumn columns ){
		
		AbstractJavaCompilation answer =  generatorJavaClass.createNewCompilation( schema, columns );
		AbstractCompilation compilation = null;
		//注意类型判定顺序不能随意变更,必须按照类的继承从最低向上判定的顺序判定.
		if(answer instanceof  Interface ){
			//Interface compilation = (Interface) compilationJava;
			compilation = new CompilationInterface((Interface) answer);
			
		}else if(answer instanceof AbstractClass  ){
			//AbstractClass compilation = (AbstractClass) compilationJava;
			compilation = new CompilationAbstractClass((AbstractClass) answer);
			
		}else if(answer instanceof Clazz  ){
			//Clazz compilation =(Clazz) compilationJava;
			compilation = new CompilationClazz( (Clazz) answer );
			
		}else if( answer instanceof  InnerClass){
			//InnerClass compilation = (InnerClass) compilationJava;
			compilation = new CompilationInnerClass((InnerClass) answer);
			
		}else if( answer instanceof  com.honey.compilation.java.Enum){
			//com.honey.compilation.java.Enum compilation = (com.honey.compilation.java.Enum) compilationJava;
			compilation = new  CompilationEnum((com.honey.compilation.java.Enum) answer);

		}else if( answer instanceof  InnerEnum){
			//InnerEnum compilation = (InnerEnum) compilationJava;
			compilation = new CompilationInnerEnum((InnerEnum) answer);
		}
		
		answer = null;
		if( compilation != null ){
			compilation.setBelongPlugin(belongPlugin) ;
			answer = compilation.doCompilation(generatorJavaClass);
		}
		return answer ;
	}
}
